package com.dykj.fireFighting.web.devhis;

import com.alibaba.fastjson.JSONObject;
import com.dykj.fireFighting.api.base.appNotification.PushModel;
import com.dykj.fireFighting.api.base.news.service.IAliMessageService;
import com.dykj.fireFighting.api.base.push.service.PushService;
import com.dykj.fireFighting.common.core.constant.CommonConstant;
import com.dykj.fireFighting.common.core.constant.WebsocketConstant;
import com.dykj.fireFighting.common.starter.redisson.service.RedisService;
import com.dykj.fireFighting.web.base.websocket.CommonWebSocket;
import com.dykj.fireFighting.web.base.websocket.entity.MoreMessage;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author fgc
 * @Date 2021/7/23 15:29
 * @ Description：
 */
@RestController
@RequestMapping("/analog/")
public class AnalogAlarmController {
    @Autowired
    private RedisService redisService;
    @DubboReference
    private IAliMessageService aliMessageService;
    @DubboReference(interfaceName = "social")
    private PushService pushService;
    @RequestMapping("fire")
    public String analogFire(){
        List<String> userIds=new ArrayList<>();
        userIds.add("8");
        userIds.add("6");
        userIds.add("5");
        userIds.add("1");
        MoreMessage moreMessage=new MoreMessage();
        moreMessage.setUserIds(userIds.toArray(new String[0]));
        moreMessage.setCmd(WebsocketConstant.CMD_FIRE);
        moreMessage.setMsgId("4");
        moreMessage.setMsgTitle("火警通知");
        moreMessage.setMsgTxt("设备发出火警通知请及时确认");
        redisService.convertAndSend("channel:moreMessage",moreMessage);
        //aliMessageService.sendAliMessage("18810406442","唐山臻旭科技有限公司","SMS_212709090","达意科技","一层西侧烟感","13:45:19");
        //aliMessageService.sendAliVoice("","18810406442","TTS_212477607","达意科技一层西侧烟感","13:45:19");
        PushModel pushModel=new PushModel();
        pushModel.setTitle("火警通知");
        pushModel.setBody("贵单位达意科技一层西侧烟感于今天13:45:19发生警情，请确认");
        pushModel.setAlias("101");
        pushModel.setClickType(CommonConstant.APPCLICKTYPE);
        pushService.pushAlias(pushModel);
        return  "true";
    }
    @RequestMapping("ysFire")
    public void analogYsFire(){
        CommonWebSocket webSocket=new CommonWebSocket();
        JSONObject json=new JSONObject();
        json.put(WebsocketConstant.MSG_CMD,WebsocketConstant.CMD_YSFIRE);
        json.put(WebsocketConstant.MSG_ID,"4");
        json.put(WebsocketConstant.MSG_TITLE,"疑似火警通知");
        json.put(WebsocketConstant.MSG_TXT,"设备发出疑似火警通知请及时确认");
        webSocket.sendOneMessage("1",json.toJSONString());
    }
}
